// Copyright 2023 The titan Authors. All rights reserved.

// Project: titan
// IDE: GoLand
// Author: fucaihe@outlook.com
// File: rpc.go
// Date: 2023/12/18 14:19:38
// Description: RPC 服务启动

package rpc

import (
	"context"
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/smallnest/rpcx/server"
)

func Run(app *server.Server, network, addr string) {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		_ = <-c
		log.Println("Gracefully shutting down...")
		_ = app.Shutdown(context.Background())
	}()

	if err := app.Serve(network, addr); err != nil {
		log.Fatalf("Listen: %s\n", err)
	}
}
